package com.ruibang.glass.equipment.service.impl.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.jdbc.StringUtils;
import com.ruibang.glass.equipment.domain.req.device.PressureVesselPageReq;
import com.ruibang.glass.equipment.entity.device.PressureVessel;
import com.ruibang.glass.equipment.mapper.device.PressureVesselMapper;
import com.ruibang.glass.equipment.service.PressureVesselService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Slf4j
@Service
public class PressureVesselServiceImpl extends ServiceImpl<PressureVesselMapper, PressureVessel> implements PressureVesselService {

    /**
     * 获取压力容器列表
     * @param pressureVesselPageReq
     * @return
     */
    @Override
    public IPage<PressureVessel> queryPressureVesselList(PressureVesselPageReq pressureVesselPageReq) {
        return baseMapper.queryPressureVesselInfo(new Page<>(pressureVesselPageReq.getPageNo(), pressureVesselPageReq.getPageSize()), pressureVesselPageReq);
    }
    /**
     * 获取压力容器新增修改
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultBody updateOrAddById(PressureVessel pressureVessel) {
        if (StringUtils.isNullOrEmpty(pressureVessel.getId())) {
            baseMapper.insert(pressureVessel);
            return ResultBody.success();
        }
        baseMapper.updateById(pressureVessel);
        return ResultBody.success();
    }

    @Override
    public List<String> getContainerCategory() {
        return baseMapper.getContainerCategory();
    }
}
